package com.goddess.yeecolor.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;
import com.goddess.yeecolor.Modle.BaoMinInfo;
import com.goddess.yeecolor.R;
import com.goddess.yeecolor.interfaceAll.OnClickListener;
import com.goddess.yeecolor.tools.ImageUtils;
import com.goddess.yeecolor.view.CircleImageView;

import java.util.List;

/**
 *已报名的适配器
 */
public class EnrollNumberAdapter extends BaseRecyclerAdapter<EnrollNumberAdapter.SimpleAdapterViewHolder> {

    private OnClickListener mOnClick;
    private List<BaoMinInfo> list;
    private Context mContxt;
    public EnrollNumberAdapter(List<BaoMinInfo> list, Context context) {
        this.list = list;
        this.mContxt=context;
    }

    @Override
    public void onBindViewHolder(SimpleAdapterViewHolder holder, int position, boolean isItem) {

        BaoMinInfo enroll = list.get(position);
        ImageUtils.getInstance().ImageStart(mContxt,enroll.getThumb(),holder.item_enrollnumber_imageview);
        holder.item_enrollnumber_name.setText(enroll.getNickname());
        holder.item_enrollnumber_time.setText(enroll.getAddtime());
        holder.item_enrollnumber_linear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int posi=holder.getLayoutPosition();
                mOnClick.OnClick(view,posi);
            }
        });
    }

    @Override
    public int getAdapterItemViewType(int position) {
        return 0;
    }

    @Override
    public int getAdapterItemCount() {
        return list.size();
    }

    @Override
    public SimpleAdapterViewHolder getViewHolder(View view) {
        return new SimpleAdapterViewHolder(view, false);
    }

    /**
     * 顶部添加数据
     * @param
     */
    public void setData(List<BaoMinInfo> lists) {

        list.clear();
        list.addAll(lists);
        notifyDataSetChanged();
    }

    public void addData(List<BaoMinInfo>lists){
//        if (isClear){
//            list.clear();
//        }
        lists.addAll(list);
        list.removeAll(list);
        list.addAll(lists);
        notifyDataSetChanged();
    }

    @Override
    public SimpleAdapterViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        View v = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.item_enrollnumber, parent, false);
        SimpleAdapterViewHolder vh = new SimpleAdapterViewHolder(v, true);
        return vh;
    }

    public void insert(BaoMinInfo person, int position) {
        insert(list, person, position);
    }

    public void remove(int position) {
        remove(list, position);
    }

    public void clear() {
        clear(list);
    }

    public class SimpleAdapterViewHolder extends RecyclerView.ViewHolder {

        public CircleImageView item_enrollnumber_imageview;
        public TextView item_enrollnumber_name;
        public TextView item_enrollnumber_time;
        private LinearLayout item_enrollnumber_linear;

        public SimpleAdapterViewHolder(View itemView, boolean isItem) {
            super(itemView);
            if (isItem) {
                item_enrollnumber_time= (TextView) itemView.findViewById(R.id.item_enrollnumber_time);
                item_enrollnumber_name= (TextView) itemView.findViewById(R.id.item_enrollnumber_name);
                item_enrollnumber_imageview= (CircleImageView) itemView.findViewById(R.id.item_enrollnumber_imageview);
                item_enrollnumber_linear= (LinearLayout) itemView.findViewById(R.id.item_enrollnumber_linear);
            }

        }
    }
    public BaoMinInfo getItem(int position) {
        if (position < list.size())
            return list.get(position);
        else
            return null;
    }
    public void setOnClickListener(OnClickListener onClickListener){
        this.mOnClick=onClickListener;
    }
}
